package com.xinruke.hostels.common.service;

import com.xinruke.hostels.common.cache.ManageUserCache;
import com.xinruke.hostels.common.cache.vo.LoginManageResultVO;
import com.xinruke.hostels.common.mapper.YewuyonghuCaozuoRizhiMapper;
import com.xinruke.hostels.common.po.YewuyonghuCaozuoRizhi;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName OperateLogService
 * @CreateDate 2019/6/18
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 操作日志Service
 */
@Service
public class OperateLogService {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    YewuyonghuCaozuoRizhiMapper yewuyonghuCaozuoRizhiMapper;
    @Autowired
    ManageUserCache manageUserCache;

    /**
     * 写入操作日志信息
     *
     * @param yewuyonghuCaozuoRizhi
     * @return
     */
    public int writeOperateLog(YewuyonghuCaozuoRizhi yewuyonghuCaozuoRizhi) {
        logger.debug("写入操作日志信息：" + new JSONObject(yewuyonghuCaozuoRizhi).toString());

        if (!YewuyonghuCaozuoRizhi.YEWUYONGHUCAOZUORIZHI_CAOZUO_DENGLU.equals(yewuyonghuCaozuoRizhi.getCaidanmingcheng())) {
            LoginManageResultVO loginManageResultVO = manageUserCache.getLoginManageUserInfo();
            yewuyonghuCaozuoRizhi.setYewuyonghuId(loginManageResultVO.getId());
            yewuyonghuCaozuoRizhi.setYewuyonghumingcheng(loginManageResultVO.getYonghuming());
        }

        return yewuyonghuCaozuoRizhiMapper.insertSelective(yewuyonghuCaozuoRizhi);
    }

    public int writeOperateLog(String caidanmingcheng, String caozuo, String beizhu) {
        YewuyonghuCaozuoRizhi yewuyonghuCaozuoRizhi = new YewuyonghuCaozuoRizhi(caidanmingcheng, caozuo, beizhu);

        return writeOperateLog(yewuyonghuCaozuoRizhi);
    }
}
